﻿using System.Windows.Controls;

using Game.Level;

namespace Game.Editor
{
    public class CampainTreeLevelsItem : TreeViewItem
    {
        readonly GameLevels _GameLevels;

        public CampainTreeLevelsItem()
        {
            _GameLevels = new GameLevels();
            Init();
        }

        public CampainTreeLevelsItem(GameLevels gameLevels)
        {
            _GameLevels = gameLevels;
            Init();
        }

        public GameLevels GameLevels
        {
            get { return _GameLevels; }
        }

        void Init()
        {
            Header = "Campaign";

            _GameLevels.Events.LevelAdded += delegate(object source, LevelEventArgs args)
            {
                var item = new CampainTreeLevelItem(this, args.GameLevel);
                Items.Add(item);
            };

            _GameLevels.Events.LevelRemoved += delegate(object source, LevelEventArgs args)
            {
                foreach (TreeViewItem item in Items)
                {
                    if (item.Tag == args.GameLevel)
                    {
                        Items.Remove(item);
                        break;
                    }
                }
            };
        }

    }
}
